import plugin from '../../lib/plugins/plugin.js'
import {
    segment
}
    from 'oicq'
import fetch from "node-fetch";

let url = ""

export class tokidokiST extends plugin {
    constructor() {
        super({
            /** 功能名称 */
            name: '搜图',
            /** 功能描述 */
            dsc: '',
            event: 'message',
            priority: 1145,
            rule: [
                {
                    reg: "^#*搜图(.*)$",
                    fnc: 'st'
                }
            ]

        })
    }

    async st(e) {
        let name = e.msg.substr(4, e.msg.length)
        console.log(name)
        url = `http://tfkapi.top/API/dtst.php?msg=${name}&type=`;
        console.log(url)
        let response = ""; //调用接口获取数据
        let res = ""; //结果json字符串转对象
        try {
            response = await fetch(url);
            res = await response.json();
            url = res.images;
        } catch {
            return
        }
        await e.reply(segment.image(url))
    }

}